package com.qububu.test.one.control;

import static com.qububu.utils.ParamConverter.assertNotEmpty;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.portlet.bind.annotation.ResourceMapping;

import com.qububu.share.article.dto.MessageInfoDto;
import com.qububu.test.one.dto.OneMapMarkerDtoLngLat;
import com.qububu.test.one.service.OneService;
import com.qububu.utils.SystemConstants;

@Controller
@RequestMapping("/testOne")
public class OneControl {

	protected Logger log = LogManager.getLogger(this.getClass());
	
	@Resource
	private OneService os;
	
	@RequestMapping("/createPage")
	public void createPage(HttpServletRequest request, HttpServletResponse response) {
		
		log.debug("|----------------OneControl-->createPage--------------|");
		log.error("|---------{error}-------OneControl-->createPage--------------|");
		
		String htmlStr = "<h1>这是一个测试</h1>";
		
		try {

			request.setCharacterEncoding("UTF-8");
			response.setContentType("text/html;charset=UTF-8");
			
			PrintWriter out = response.getWriter();
			
			out.println(htmlStr);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	@RequestMapping("/redirecter")
	public String redricter() {
		
		log.info("|---------{info}-------OneControl-->redricter--------------|");
		
		return "redirect:../pay/alipay";
	}
	
	@RequestMapping("/testAddArticle")
	public String addArticle() {
	
		log.info("|---------{info}-------OneControl-->redricter--------------|");
		
		return "test";
	}
	@RequestMapping("/testMap")
	public String testMap(){
		
		return "testMap";
	}
	@RequestMapping(value="/mapMarkerData")
	@ResponseBody
	public Map<String,Object> mapMarkerData(HttpServletRequest request,HttpServletResponse response){
		
		String num = request.getParameter("clickNumber");
		int  marKerTypeNum = Integer.parseInt(num) ;
		Map<String, Object> markerMapLngLat = new HashMap<String, Object>();
		List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
		
		OneMapMarkerDtoLngLat mapMarkerDtoLngLat = new OneMapMarkerDtoLngLat();
		Map<String , Object> josonMap = new HashMap<String, Object>();
		Map<String , Object> josonMap1 = new HashMap<String, Object>();
		
			if(marKerTypeNum == 0){
				double x = 103.98757;
				double y = 30.580274;
				mapMarkerDtoLngLat.setX(x);
				mapMarkerDtoLngLat.setY(y);
				
				
				josonMap.put("x",x);
				josonMap.put("y",y);
				josonMap.put("title","住宿(金坤静园小区东)");
				josonMap.put("address","天津南路503号 附近");
				josonMap.put("phoneNumber","18200388503");
				list.add(josonMap);
				
				josonMap1.put("x","103.98757");
				josonMap1.put("y","34.580274");
				josonMap1.put("title","山水宾馆");
				josonMap1.put("address","皮库胡同45");
				josonMap1.put("phoneNumber","010-66063388");
				list.add(josonMap1);
			}
			if(marKerTypeNum == 1){
				double x = 100.98757;
				double y = 30.580274;
				mapMarkerDtoLngLat.setX(x);
				mapMarkerDtoLngLat.setY(y);
				
				
				josonMap.put("x",x);
				josonMap.put("y",y);
				josonMap.put("title","住宿(金坤静园小区东XXXX)");
				josonMap.put("address","天津南路503号 附近");
				josonMap.put("phoneNumber","18200388503");
				list.add(josonMap);
				
				josonMap1.put("x","100.98757");
				josonMap1.put("y","34.580274");
				josonMap1.put("title","山水宾馆XXXX");
				josonMap1.put("address","皮库胡同45");
				josonMap1.put("phoneNumber","010-66063388");
				list.add(josonMap1);
			}
				markerMapLngLat.put("list",list);
				System.out.print("=============="+marKerTypeNum+"===============");
		return markerMapLngLat;
		
		
	}
	@RequestMapping("/kind")
	public String kind(){
		
		return "testKind";
	}
}
